home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / games1 / cc2.zip / CC2.C next >
Text File  |  1993-04-03  |  11KB  |  316 lines

  1. #include <stdio.h>
  2. #include <io.h>
  3. #include <fcntl.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <time.h>  /* for randomize only? */
  7.  
  8. int loop,loop2;
  9. unsigned int res;
  10. unsigned char svefile[0x93e0];
  11.  
  12. unsigned char *uid[0x1c];
  13. unsigned char *u[1024];
  14. unsigned char *city[128];
  15. char *ruler[8];
  16. char *emp[8];
  17. int bucks[8];
  18. char *cityname[256];
  19.  
  20. char ch,mainquit;
  21. FILE *fp2;
  22.  
  23. main(argc,argv)
  24. int argc;
  25. char **argv;
  26. {
  27.  
  28.   ch = 0x00;
  29.   clrscr();
  30.   if (argc != 2) {
  31.      argv[1] = (char *)malloc(20);
  32.      printf("Please enter an input .sve file: ");
  33.      scanf("%s",argv[1]);
  34.   }
  35.   printf("Input file is %s.\n",argv[1]);
  36.  
  37.   /* read entire file in at once */
  38.   if ((fp2 = fopen(argv[1],"rb")) == NULL) { printf("Cannot open input file.\n"); exit(1); }
  39.   if ((res = fread(svefile,0x93e0,1,fp2)) != 1) { printf("Only got first %x bytes.\n",res); exit(1); }
  40.   fclose(fp2);
  41.  
  42.   /* try to assign uid pointers to an area in svefile[] */
  43.   printf("Reading unit type information...");
  44.   for (loop=0; loop<0x1c; loop++) {
  45.     uid[loop] = svefile + 0x2308 + 34*loop;
  46.     putch('.');
  47.   }
  48.   printf("\n");
  49.  
  50.   /* try to assign unit list to an area in svefile[] */
  51.   printf("Reading unit information...");
  52.   for (loop=0; loop<1024; loop++) {
  53.     u[loop] = svefile + 0x26c0 + 12*loop;
  54.     putch('.');
  55.   }
  56.  
  57.   /* pointers to empire stats */
  58.   printf("Getting ruler info...");
  59.   for (loop=0; loop<8; loop++) {
  60.     ruler[loop] = svefile + 0x10 + 14*loop;
  61.     emp[loop] = svefile + 0x80 + 12*loop;
  62.     bucks[loop] = *(svefile + 0x138 + 2*loop + 1) *0x100 + *(svefile + 0x138 + 2*loop ) ;
  63.     putch('.');
  64.   }
  65.  
  66.   /* city stuff */
  67.   printf("Getting city info...");
  68.   for (loop=0; loop<256; loop++) {
  69.     cityname[loop] = svefile + 0x6970 + 13*loop;
  70.     putch('.');
  71.   }
  72.   for (loop=0; loop<128; loop++) {
  73.     city[loop] = svefile + 0x1508 + 28*loop;
  74.     putch('.');
  75.   }
  76.  
  77.   mainquit = 0;
  78.   do {
  79.     clrscr();
  80.     printf("Currently editing %s.  CivCheat main menu.\n",argv[1]);
  81.     printf("  a) Edit military unit type attributes.\n");
  82.     printf("  b) Edit a specific unit's atttributes.\n");
  83.     printf("  c) Edit player stats, money, etc.\n");
  84.     printf("  d) Edit city pop, food, res, works, etc.\n");
  85.     printf("ESC) Quit to play more Civ.\n");
  86.     gotoxy(1,20); printf("Choose your poison : ");
  87.     ch=getche();
  88.     switch (ch) {
  89.       case 'a': edituid(); break;
  90.       case 'b': editu(); break;
  91.       case 'c': editstats(); break;
  92.       case 'd': editcity2(); break;
  93.       case 27: mainquit = 1; break;
  94.     }
  95.   } while (!mainquit);
  96.  
  97.   /* try to rewrite file. */
  98.   if ((fp2 = fopen(argv[1],"wb")) == NULL) { printf("Cannot open output file.\n"); exit(1); }
  99.   if ((res = fwrite(svefile,0x93e0,1,fp2)) != 1) { printf("Only wrote first %x bytes.\n",res); exit(1); }
  100.   fclose(fp2);
  101.   quitting();
  102.   exit(0);
  103.  
  104. }
  105.  
  106. editu()
  107. {
  108.   int num,page,pages,count,loop,point[1024]; /* list of all active units */
  109.   unsigned char dum1,dum2;
  110.   count = 0;
  111.   for (loop = 0; loop<1024; loop++) {
  112.     if (*(u[loop] + 3) != 0xff) point[count++] = loop;
  113.   }
  114.   pages = ((count - 1)/21);
  115.   page = 0;
  116.   do {
  117.     clrscr();
  118.     gotoxy(1,1); printf("Units page %d of %d.",page,pages);
  119.     for (loop=0; loop<20; loop++) {
  120.       gotoxy(1,loop+2);
  121.       num = loop + page*20;
  122.       if (num<count) {
  123.         printf("%4d) %s unit from %s (#%d) is at %d,%d. ",
  124.            num,
  125.            uid[*(u[point[num]]+3)],
  126.            cityname[*(city[*(u[point[num]]+11)]+22)],
  127.            *(u[point[num]]+11),
  128.            *(u[point[num]]+1),
  129.            *(u[point[num]]+2));
  130.         if (*(u[point[num]]+6) == 0xff) {
  131.              switch(*(u[point[num]]+7)) {
  132.                 case 0x1d: printf("(Fortified)"); break;
  133.                 case 0x18: printf("(Sleeping)"); break;
  134.              }
  135.         } else {
  136.              printf("(Unit is moving to %d,%d)",*(u[point[num]]+6),*(u[point[num]]+7));
  137.         }
  138.         printf("\n");
  139.       }
  140.     }
  141.     gotoxy(1,22); printf("Commands are PgUp, PgDn, E to edit, ESC to quit.");
  142.     ch=getch();
  143.     switch (toupper(ch)) {
  144.       case 27: break;
  145.       case 'E':
  146.          do {
  147.            gotoxy(1,23); printf("Which unit [0-%d] : ",count-1);
  148.            scanf("%d",&num);
  149.          } while ((num<0) || (num>=count));
  150.          if ((num>=(page*20)) && (num<=(page*20+19))) {
  151.             gotoxy(1,num-20*page+2); printf("->"); }
  152.          gotoxy(1,24); printf("X,Y pos [%d,%d] : ",*(u[point[num]]+1),*(u[point[num]]+2));
  153.             /* do i have to read em as integers then convert to char and store
  154.                because scanf has no format command to read in bytes? */
  155.          scanf("%d,%d",&dum1,&dum2);
  156.          *(u[point[num]]+1) = dum1; *(u[point[num]]+2) = dum2;
  157.          gotoxy(40,24); printf("New supporting city [%d] : ",*(u[point[num]]+11));
  158.          scanf("%d",&dum1);
  159.          *(u[point[num]]+11) = dum1;
  160.          clrscr();
  161.          printf("Unit types available.\n");
  162.          for (loop=0; loop<0x1c; loop++) printf("%c) %-17s",loop+96,uid[loop]);
  163.          printf("Unit is currently %s.  New type: ",uid[*(u[point[num]]+3)]); /* these pointers are getting out of hand! */
  164.          do { ch=getch(); } while ((ch < 96) || (ch > 123));
  165.          *(u[point[num]]+3) = ch-96;
  166.        break;
  167.       case 00: ch=getch();
  168.          switch (ch) {
  169.            case 73: page = (page == 0) ? 0 : page-1; break;
  170.            case 81: page = (page == pages) ? pages : page+1; break;
  171.          }
  172.          break;
  173.       }
  174.   } while (ch != 27);
  175. }
  176.  
  177. edituid()
  178. {
  179.   int loop;
  180.   do {
  181.     clrscr();
  182.     gotoxy(1,1); printf("Format is Unit Name : Attack / Defense / Move / Resources ");
  183.     for (loop=0; loop<0x1c; loop++) {
  184.       gotoxy((loop>=14) ? 40 : 1, (loop>=14) ? loop-12 : loop+2);
  185.       printf("%c) %12s:%2d/%2d/%2d/%3d",loop+96,uid[loop],*(uid[loop]+20),*(uid[loop]+22),
  186.               *(uid[loop]+16),*(uid[loop]+24)*10);
  187.     }
  188.     do {
  189.       loop = -1;
  190.       gotoxy(1,20); printf("Which unit [letter, ESC to quit] : ");
  191.       ch=getche();
  192.       if ((ch >= 96) && (ch <= 123)) loop = ch-96;
  193.     } while ((loop == -1) && (ch != 27));
  194.     if (ch != 27) {
  195.        gotoxy(1,21);
  196.        printf("New Att [%d] : ",*(uid[loop]+20)); scanf("%d",uid[loop]+20);
  197.        printf("New Def [%d] : ",*(uid[loop]+22)); scanf("%d",uid[loop]+22);
  198.        printf("New Mov [%d] : ",*(uid[loop]+16)); scanf("%d",uid[loop]+16);
  199.        printf("New Res [%d] : ",*(uid[loop]+24)); scanf("%d",uid[loop]+24);
  200.     }
  201.   } while (ch != 27);
  202. }
  203.  
  204. editstats()
  205. {
  206.   int loop;
  207.   do {
  208.     clrscr();
  209.     printf("The following players exist.");
  210.     for (loop=0; loop<8; loop++) {
  211.       gotoxy(1,2+loop);
  212.       printf(" %c) Emporer %s of the %s has %d bucks.",loop+97,ruler[loop],emp[loop],bucks[loop]);
  213.     }
  214.     gotoxy(1,20); printf("Edit which one [letter, ESC to quit] : ");
  215.     ch = getche();
  216.     if (ch != 27) {
  217.        loop = ch-97;
  218.        if ((loop>=0) && (loop<=8)) {
  219.           gotoxy(1,21); printf("New bucks [32767 max] : "); scanf("%d",&bucks[loop]);
  220.           gotoxy(1,22); printf("Change empire name? [Y/N] : ");
  221.           do { ch=toupper(getch()); } while ((ch != 'Y') && (ch != 'N')); putch(ch);
  222.           if (ch == 'Y') { printf("  New name: "); scanf("%s",emp[loop]); }
  223.           gotoxy(1,23); printf("Change emporer name? [Y/N] : ");
  224.           do { ch=toupper(getch()); } while ((ch != 'Y') && (ch != 'N')); putch(ch);
  225.           if (ch == 'Y') { printf("  New name: "); scanf("%s",ruler[loop]); }
  226.        }
  227.     }
  228.   } while (ch != 27);
  229. }
  230.  
  231. editcity2()
  232. {
  233.   int point[128];  /* pointer to active cities */
  234.   int loop,count,page,pages,num;
  235.   unsigned int dum1,dum2,dum3,dum4;
  236.  
  237.   count = 0;
  238.   for (loop = 0; loop<128; loop++) {
  239.     if (*(city[loop] + 6) != 0xff) point[count++] = loop;
  240.   }
  241.   pages = ((count - 1)/21);
  242.   page = 0;
  243.  
  244.   do {
  245.     clrscr();
  246.     gotoxy(1,1); printf("City page %d of %d.",page,pages);
  247.     for (loop=0; loop<20; loop++) {
  248.       gotoxy(1,loop+2);
  249.       num = loop + page*20;
  250.       if (num<count) {
  251.          printf("%4d) %s at (%d,%d) has %d pop, %d food, %d res. Works = %02x%02x%02x%02x.",
  252.            num,
  253.            cityname[*(city[point[num]]+22)],
  254.            *(city[point[num]]+4),
  255.            *(city[point[num]]+5),
  256.            *(city[point[num]]+7),
  257.            *(city[point[num]]+12),
  258.            *(city[point[num]]+14),
  259.            *(city[point[num]]),
  260.            *(city[point[num]]+1),
  261.            *(city[point[num]]+2),
  262.            *(city[point[num]]+3));
  263.       }
  264.     }
  265.     gotoxy(1,22); printf("Commands are PgUp, PgDn, E to edit, ESC to quit.");
  266.     ch=getch();
  267.     switch (toupper(ch)) {
  268.       case 27: break;
  269.       case 'E':
  270.          do {
  271.            gotoxy(1,23); printf("Which city [0-%d] : ",count-1);
  272.            scanf("%d",&num);
  273.          } while ((num<0) || (num>=count));
  274.          if ((num>=(page*20)) && (num<=(page*20+19))) {
  275.             gotoxy(1,num-20*page+2); printf("->"); }
  276.          gotoxy(1,24); printf("New population [%d] : ",*(city[point[num]]+7));
  277.          scanf("%d",city[point[num]]+7);
  278.          gotoxy(27,24); printf("New food [%d] : ",*(city[point[num]]+12));
  279.          scanf("%d",city[point[num]]+12);
  280.          gotoxy(50,24); printf("New res [%d] : ",*(city[point[num]]+14));
  281.          scanf("%d",city[point[num]]+14);
  282.          gotoxy(1,25); printf("New Works Map (4 hex bytes separated by commas please) : ");
  283.          scanf("%x,%x,%x,%x",&dum1,&dum2,&dum3,&dum4);
  284.          *(city[point[num]]) = dum1;
  285.          *(city[point[num]]+1) = dum2;
  286.          *(city[point[num]]+2) = dum3;
  287.          *(city[point[num]]+3) = dum4;
  288.        break;
  289.       case 00: ch=getch();
  290.          switch (ch) {
  291.            case 73: page = (page == 0) ? 0 : page-1; break;
  292.            case 81: page = (page == pages) ? pages : page+1; break;
  293.          }
  294.          break;
  295.       }
  296.   } while (ch != 27);
  297. }
  298.  
  299. quitting()
  300. {
  301.   char *data;
  302.   clrscr();
  303.   randomize();
  304.   printf("What did you think of this program?\n");
  305.   switch (random(5)) {
  306.      case 0 : data = "Sid Meyer is really smart but Steve Norton is brilliant!"; break;
  307.      case 1 : data = "Ever take a needle, dip it in acid and stick it in your eye? It's like that."; break;
  308.      case 2 : data = "So this is what college students do when they're bored."; break;
  309.      case 3 : data = "Cheat?  Who needs to cheat at Civ?  Its easy!"; break;
  310.      case 4 : data = "grog need tanks. Grog Need Tanks! GROG NEED TANKS!!!"; break;
  311.   }
  312.   do {
  313.     ch=getch(); putch(*data++);
  314.   } while ((*data != 0) && (ch != 27));
  315.   printf("\nBy the way, you can press ESC to bypass the comments.\n");
  316. }